from web_practice.page_object.wx_base_page import BasePage


class WxContactPage(BasePage):
    _baseurl = 'https://work.weixin.qq.com/wework_admin/frame#contacts'
    _addMember = ('CSS', '.qui_btn.ww_btn.js_add_member')
    _member_name_list = ('CSS', '.member_colRight_memberTable_td:nth-child(2)')
    _member_phone_list = ('CSS', '.member_colRight_memberTable_td:nth-child(5)')

    def goto_add_member(self):
        """
        跳转添加成员
        :return:
        """
        from web_practice.page_object.wx_add_member_page import WxAddMemberPage
        self.find_web_element(*self._addMember).click()
        return WxAddMemberPage(self.web_driver)

    def get_contacts_list(self):
        """
        获取添加的成员
        :return:
        """
        # 获取不是创建人的成员的姓名列表
        contacts_name_list = [i.text for i in self.find_web_elements(*self._member_name_list) if i.text != '刘伟']
        # 获取不是创建人的成员的手机号列表
        contacts_phone_list = [i.text for i in self.find_web_elements(*self._member_phone_list) if
                               i.text != '18916473159']
        # 两个列表组成字典
        result = list([{'username': i[0], 'phone': i[1]} for i in
                       zip(contacts_name_list, contacts_phone_list)])
        return result
